/**
 * 
 */
package com.common.bean;

import org.json.JSONException;
import org.json.JSONObject;

import com.common.StarAppConst.IM_MESSAGE_KEY;
import com.common.allCommon.JSONObjecthelper;

import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable.Creator;
import android.text.TextUtils;

/**
 * 用户获得道具消息数据存储类 <br>
 * Created 2014-11-6 上午10:18:02
 * 
 * @version
 * @author ChuXY
 * 
 * @see
 */
public class UserArticalGottenData extends AppMsgData implements
		ICommonImDataStruct, Parcelable {

	/** 消息类型 */
	private String mType = "";
	/**
	 * 消息内容
	 */
	private String mMessage = "";

	/** 时间戳 */
	private long mTime = 0;

	/** 昵称 */
	private String mUniqueName = "";

	/** 用户id */
	private long mUid = 0;

	/** 背包ID */
	private long mTid = 0;

	/**头像id*/
	private long mFileId=0;
	
	/**物品类型id*/
	private long mItemType=0;
	
	/**物品名*/
	private String mTitle="";
	
	
	/**
	 * Creates a new instance of UserArticalGottenData.
	 * <br>Created 2014-11-7 下午5:13:16
	 * @param in
	 */
	public UserArticalGottenData(Parcel in) {
		mMessage = in.readString();
		mTime = in.readLong();
		mType = in.readString();
		mUniqueName = in.readString();
		mUid = in.readLong();
		mTid = in.readLong();
		mFileId=in.readLong();
		mItemType=in.readLong();
		mTitle=in.readString();
	}

	/**
	 * @return the mItemType
	 */
	public long getItemType() {
		return mItemType;
	}

	/**
	 * @param mItemType the mItemType to set
	 */
	public void setItemType(long itemType) {
		this.mItemType = itemType;
	}

	/**
	 * @return the mTitle
	 */
	public String getTitle() {
		return mTitle;
	}

	/**
	 * @param mTitle the mTitle to set
	 */
	public void setTitle(String title) {
		this.mTitle = title;
	}
	/**
	 * @return the mFileId
	 */
	public long getFileId() {
		return mFileId;
	}

	/**
	 * @param mFileId the mFileId to set
	 */
	public void setFileId(long fileId) {
		this.mFileId = fileId;
	}

	/**
	 * 获取背包id
	 * 
	 * @return the mTid
	 */
	public long getmTid() {
		return mTid;
	}

	/**
	 * 设置tid
	 * 
	 * @param tid
	 *            the mTid to set
	 */
	public void setmTid(long tid) {
		this.mTid = tid;
	}


	@Override
	protected void parcelInData(Parcel in) {
		super.parcelInData(in);
		mMessage = in.readString();
		mTime = in.readLong();
		mType = in.readString();
		mUniqueName = in.readString();
		mUid = in.readLong();
		mFileId=in.readLong();
		mItemType=in.readLong();
		mTitle=in.readString();
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		super.writeToParcel(dest, flags);
		dest.writeString(mMessage);
		dest.writeLong(mTime);
		dest.writeString(mType);
		dest.writeString(mUniqueName);
		dest.writeLong(mUid);
		dest.writeLong(mFileId);
		dest.writeLong(mItemType);
		dest.writeString(mTitle);
	}

	@Override
	public void parseJson(String strJson) {
		if (TextUtils.isEmpty(strJson)) {
			return;
		}

		JSONObject jsonData = null;
		try {
			jsonData = new JSONObject(strJson);
		} catch (JSONException e) {
			return;
		}
		mType = JSONObjecthelper.getString(jsonData, IM_MESSAGE_KEY.TAG_TYPE);
		mMessage = JSONObjecthelper.getString(jsonData, IM_MESSAGE_KEY.TAG_MSG);
		mTime = JSONObjecthelper.getLong(jsonData, IM_MESSAGE_KEY.TAG_TIME);
		mUid = JSONObjecthelper.getLong(jsonData, IM_MESSAGE_KEY.TAG_USERID);
		mUniqueName = JSONObjecthelper.getString(jsonData,
				IM_MESSAGE_KEY.TAG_UNIQUENAME);
		mFileId = JSONObjecthelper.getLong(jsonData, IM_MESSAGE_KEY.TAG_CHECK_CODE);
		mItemType = JSONObjecthelper.getLong(jsonData, IM_MESSAGE_KEY.TAG_ITEM_TYPE);
		mTitle = JSONObjecthelper.getString(jsonData, IM_MESSAGE_KEY.TAG_TITLE);
	}

	@Override
	public String getType() {
		return mType;
	}

	@Override
	public void setType(String type) {
		mType = type;
	}

	@Override
	public String getMessage() {
		return mMessage;
	}

	@Override
	public void setMessage(String message) {
		mMessage = message;
	}

	@Override
	public long getTime() {
		return mTime;
	}

	@Override
	public void setTime(long time) {
		mTime = time;
	}

	@Override
	public String getUniqueName() {
		return mUniqueName;
	}

	@Override
	public void setUniqueName(String uniqueName) {
		mUniqueName = uniqueName;
	}

	@Override
	public long getUid() {
		return mUid;
	}

	@Override
	public void setUid(long uid) {
		mUid = uid;
	}

	@Override
	public int describeContents() {
		return 0;
	}
	
	public static final Parcelable.Creator<UserArticalGottenData> CREATOR = new Creator<UserArticalGottenData>() {

		@Override
		public UserArticalGottenData[] newArray(int size) {
			return new UserArticalGottenData[size];
		}

		@Override
		public UserArticalGottenData createFromParcel(Parcel in) {
			return new UserArticalGottenData(in);
		}
	};
	
	@Override
	public String transDataToJSON() {
		JSONObject json=new JSONObject();
		try {
			json.put(IM_MESSAGE_KEY.TAG_TYPE, mType);
			json.put(IM_MESSAGE_KEY.TAG_MSG, mMessage);
			json.put(IM_MESSAGE_KEY.TAG_TIME, mTime);
			json.put(IM_MESSAGE_KEY.TAG_UNIQUENAME, mUniqueName);
			json.put(IM_MESSAGE_KEY.TAG_USERID, mUid);
			json.put(IM_MESSAGE_KEY.TAG_CHECK_CODE, mFileId);
			json.put(IM_MESSAGE_KEY.TAG_ITEM_TYPE, mItemType);
			json.put(IM_MESSAGE_KEY.TAG_TITLE, mTitle);
		} catch (JSONException e) {
			e.printStackTrace();
			return null;
		}
		return json.toString();
	}
	
	@Override
	public void setDataFromJSON(String jsonString) {
		parseJson(jsonString);
	}

	
	/**
	 * Creates a new instance of UserArticalGottenData.
	 * <br>Created 2014-11-7 下午5:23:34
	 */
	public UserArticalGottenData() {
		super();
	}

	@Override
	public long getLongExtraData() {
		return 0;
	}

	/**
	 * 
	 * <br>Created 2014-11-30 下午4:08:57
	 * @return
	 * @author       ChuXY	
	*/
	
	@Override
	public String getStringExtraData() {
		// TODO Auto-generated method stub
		return null;
	}

	
}
